package com.hup.minicontroller.common.hardware;

import com.hup.utils.commons.hardware.HRobotJni;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * 控制设备的工具类,实现功能:触摸事件,按下按钮事件
 */
public class ActionMocker {
    private static final String TAG = ActionMocker.class.getSimpleName();

    private Robot robot;

    public ActionMocker() throws AWTException {
        robot = new Robot();
    }

    public void click(int x, int y) {
        HRobotJni.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.delay(50);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    }


    public void press(int x, int y) {
        HRobotJni.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    }


    public void up(int x, int y) {
        HRobotJni.mouseMove(x, y);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    }


    public void move(int x, int y) {
        HRobotJni.mouseMove(x, y);
    }


    /**
     * 返回:alt+left,不会十分通用
     */
    public void buttonBack() {
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_LEFT);
        robot.delay(50);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.keyRelease(KeyEvent.VK_LEFT);
    }

    /**
     * 显示桌面
     */
    public void buttonHome() {
        robot.keyPress(KeyEvent.VK_WINDOWS);
        robot.keyPress(KeyEvent.VK_D);
        robot.delay(50);
        robot.keyRelease(KeyEvent.VK_WINDOWS);
        robot.keyRelease(KeyEvent.VK_D);
    }

    /**
     * 打开任务窗口
     */
    public void buttonApp() {
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_TAB);
        robot.delay(50);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.keyRelease(KeyEvent.VK_TAB);
    }

}
